package com.controller.lx;

import java.text.ParseException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.entity.Complain;
import com.service.ServiceException;
import com.service.lx.ComplainService;
import com.utils.Pager;
import com.utils.Result;

@Controller
public class ComplainController {
	@Autowired
	private ComplainService complainService;
	
	/**
	 * 快速查询
	 * @param field
	 * @param curpage
	 * @param pagesize
	 * @return
	 */
	@PostMapping("/complain_fastselect_")
	@ResponseBody
	public Page<Complain> fastselect(@RequestParam("field") String field, 
			@RequestParam("curpage") Integer curpage, 
			@RequestParam("pagesize") Integer pagesize){
		return complainService.findFastAllComplains(field, curpage, pagesize);
	}
	
	/**
	 * 逻辑删除
	 * @param Id
	 * @throws ServiceException
	 */
	@DeleteMapping("/complain_ifdelete_")
	@ResponseBody
	public Result UpdateIfdelete(Long Id){
		complainService.UpdateComplainIfdelete(Id);
		return Result.SUCCESS;
	}

	/**
	 * 批量删除
	 * @param qaIds
	 */
	@PostMapping("/complain_delete_arr_")
	@ResponseBody
	public Result deletBatchRoles(@RequestBody JSONArray Ids) {
		complainService.deletArrIfDelete(JSONObject.parseArray(Ids.toString(), Long.class));
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改
	 * @param complain
	 * @throws ServiceException
	 */
	@PostMapping("/complain_addandupdate_")
	@ResponseBody
	public Result addAndUpdate(@RequestBody Complain complain){
		complainService.addAndUpdateComplain(complain);
		return Result.SUCCESS;
	}
	
	/**
	 * 高级查询
	 * @param map
	 * @return 
	 * @throws ParseException 
	 * @throws ServiceException
	 */
	@PostMapping("/complain_hightselect_")
	@ResponseBody
	public Pager<Complain> hightselect(@RequestBody Map map){
		return complainService.findHighAllComplains(map);
	}
}
